#ifndef CHATCLIENT_H
#define CHATCLIENT_H

#include <QWidget>
#include <QCloseEvent>
#include <QAbstractItemModel>
#include <QMap>

#include "globalvars.h"
#include "msgsocket.h"
#include "sublogin.h"
#include "privateform.h"

namespace Ui {
class ChatClient;
}

class ChatClient : public QWidget
{
    Q_OBJECT

public:
    explicit ChatClient(QWidget *parent = nullptr);
    ~ChatClient();

    void initForm();

protected:
    void closeEvent(QCloseEvent *ev);

public slots:
    void slotUserRegister(UserInfo info);
    void slotUserRegisterResult(bool res);

    void slotUserLogin(QString id, QString pswd);
    void slotUserLoginResult(bool res, QString msg);

    void slotUserLogout();
    void slotUserLogoutResult(bool res);

    void slotGetOnlineUser();
    void slotGetOnlineUserResult(bool res);

    void slotSendMsgAll();
    void slotGetMsgAllResult(QString msg);

    void slotSendMsgPrivate(QString id, QString msg);
    void slotGetMsgPrivateResult(QString id, QString msg);
    void slotPrivateFormClose(QString id);

private slots:
    void on_pushButton_clicked();

    void on_tableWidget_clicked(const QModelIndex &index);

private:
    Ui::ChatClient *ui;
    bool m_isCloseSystem;

    MsgSocket* m_msgSocket;
    SubLogin* m_subLogin;

    QMap<QString, PrivateForm*> m_privateFormMap;
};

#endif // CHATCLIENT_H
